# -*- encoding:utf-8 -*-
import numpy as np
from datautils import datasets

from sklearn import metrics
# from sklearn import datasets
from sklearn.model_selection import train_test_split  # 原文中cross_validation已过时改为model_selection
from sklearn.linear_model import LinearRegression, Ridge, RidgeCV, SGDRegressor
import matplotlib.pyplot as plt
from sklearn.model_selection import cross_val_predict

'''
reference:https://my.oschina.net/u/2245781/blog/1855834
'''

path = "./data/face_mesh_communication.csv"
# path = "./data/mesh_calculation.csv"

loaded_data = datasets(path)
loaded_data.read()
data_X = loaded_data.data
data_y = loaded_data.target

X_train, X_test, y_train, y_test = train_test_split(data_X, data_y, test_size=0.2)
# print(shape(X_train))
# print shape(X_test)

model = LinearRegression()
model.fit(X_train, y_train)
print("系数：", model.coef_)
# print(model.intercept_)

y_pred = model.predict(X_test)
print("MSE:", metrics.mean_squared_error(y_test, y_pred))
predicted = cross_val_predict(model, data_X, data_y, cv=10)
print("MSE:", metrics.mean_squared_error(data_y, predicted))

plt.scatter(data_y, predicted, color='y', marker='o')
plt.scatter(data_y, data_y, color='g', marker='+')
plt.show()

